import XEUtils from 'xe-utils/methods';

export default class CronUtil {
  /**
   * CRON表达式前面的"*"替换为"0"
   * @param cron 
   */
  public static replaceCron(cron: string) {
    if (XEUtils.isEmpty(cron)) {
      return;
    }

    let resultCron: string = '';

    const emptyStr: string = ' ';

    const cronItemArray: string[] = cron.split(emptyStr);

    let isExists: boolean = false;

    XEUtils.arrayEach(cronItemArray, (item, key) => {
      if (item == '*' && isExists == false) {
        resultCron += ('0' + emptyStr)
      } else {
        resultCron += (item + emptyStr);
        isExists = true;
      }
    })

    resultCron = XEUtils.trim(resultCron);

    return resultCron;
  }
}
